using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Commons;
using System.Drawing.Drawing2D;
using WP.Modules;
using System.Runtime.InteropServices;
using System.Collections;
namespace MaxLeaf
{
    public partial class frmUnitCnv : BaseQryRpt 
    {
        public frmUnitCnv()
        {
            InitializeComponent();
            this.LoadAllControl(new ArrayList(this.Controls));  
        }

        private Point mstartPoint;

        //private int mintLookUpKey;

        private void btnOK_Click(object sender, EventArgs e)
        {
            txtQtyTo.Text = DataFunctions.UnitCnv(txtItemNumber.Text, Convert.ToDouble(txtQtyFrom.Text), txtUnitFrom.Text, txtUnitTo.Text).ToString();
        }
        private void frmUnitCnv_Load(object sender, EventArgs e)
        {
            txtItemNumber.Text = "";
            txtQtyFrom.Text = "0.00";
            txtUnitFrom.Text = "";
            txtQtyTo.Text = "";
            txtUnitTo.Text = "";
            txtFunction.Text = "";
            //mintLookUpKey = gKeyLookUp;
            DataFunctions.SetDftLanguage(this.arraycontrols, this.Name);   
        }
        private void textChanged(object sender, EventArgs e)
        {
            txtFunction.Text = "UnitCnv('" + txtItemNumber.Text.Trim() + "'," + txtQtyFrom.Text.Trim() + ",'" + txtUnitFrom.Text.Trim() + "','" + txtUnitTo.Text.Trim() + "',Result)";
        }
        private void ubtItemNumber_Click(object sender, EventArgs e)
        {
            string strSQL = WP.Commons.BaseFunctions.GetLookUpSQL("ImInvMaster");
            if (strSQL == "")
            {
                strSQL = "select * from ImInvMaster";
            }

            

            frmLookUp frmlookup = new frmLookUp(strSQL, "ItemMaster");
            frmlookup.ShowDialog();
            if (frmlookup.HaveReturnValue)
            {
                txtItemNumber.Text = frmlookup.GetReturnValue("ItemNo");
            }
            frmlookup.Close();
        }
        private void ubtUnitFrom_Click(object sender, EventArgs e)
        {
            string strSQL = "SELECT FromUnit, Conversion, ToUnit, Link, RecId FROM imUnitConversionHdr";
            frmLookUp frmlookup = new frmLookUp(strSQL, "Unit");
            frmlookup.ShowDialog();
            if (frmlookup.HaveReturnValue)
            {
                txtUnitFrom.Text = frmlookup.GetReturnValue("FromUnit");
            }
            frmlookup.Close();
        }
        private void ubtUnitTo_Click(object sender, EventArgs e)
        {
            string strSQL = "SELECT FromUnit, Conversion, ToUnit, Link, RecId FROM imUnitConversionHdr";
            string strMtnFormName = "frmimUnitConversionHdrMtn";
            frmLookUp frmlookup = new frmLookUp(strSQL, "Unit");
            frmlookup.ShowDialog();
            if (frmlookup.HaveReturnValue)
            {
                txtUnitTo.Text = frmlookup.GetReturnValue("ToUnit");
            }
            frmlookup.Close();
        }

        private void txtItemNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {

        }
        private void txtQtyFrom_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {

        }
        private void txtUnitFrom_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {

        }
        private void txtUnitTo_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {

        }
        private void txtQtyTo_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {

        }
        private void txtItemNumber_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {

            if (e.KeyCode == SysVar.SystemKey.LookUPKey || e.KeyCode == SysVar.SystemKey.LookUPSecKey)
            {
                ubtItemNumber_Click(sender, e);
            }
        }
        private void txtQtyFrom_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {

        }
        private void txtUnitFrom_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {

            if (e.KeyCode == SysVar.SystemKey.LookUPKey || e.KeyCode == SysVar.SystemKey.LookUPSecKey)
            {
               ubtUnitFrom_Click(sender, e);
            }

        }
        private void txtUnitTo_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == SysVar.SystemKey.LookUPKey || e.KeyCode == SysVar.SystemKey.LookUPSecKey)
            {
                ubtUnitTo_Click(sender, e);
            }
        }
        private void txtQtyTo_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
        }

        private void ShowRectangle(Control con)
        {
            Graphics dc = this.CreateGraphics();
            Pen blackPen = new Pen(Color.Black, 1);
            blackPen.DashStyle = DashStyle.Dot ;
            int  x0, y0, x1, y1;
            x0 = con.Left - 1;
            y0 = con.Top - 1;
            x1 = x0 + con.Width + 1;
            y1 = y0 + con.Height + 1;
            Rectangle rect = new Rectangle(x0, y0, x1 - x0, y1 - y0);
            dc.DrawRectangle(blackPen, rect);
            blackPen.DashStyle = DashStyle.Solid;  

            Brush blackBrush = new HatchBrush( HatchStyle.DottedGrid,Color.Black);
            float d = 2f;
            dc.DrawEllipse(blackPen, (float)x0 - d, (float)y0 - d, 2 * d, 2 * d);
            dc.DrawEllipse(blackPen, (float)x0 - d, (float)y1 - d, 2 * d, 2 * d);
            dc.DrawEllipse(blackPen, (float)x1 - d, (float)y0 - d, 2 * d, 2 * d);
            dc.DrawEllipse(blackPen, (float)x1 - d, (float)y1 - d, 2 * d, 2 * d);    
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;

        private void frmUnitCnv_FormClosing(object sender, FormClosingEventArgs e)
        {
            DataFunctions.InitiateLanguageInfo(this.arraycontrols,this.arrayLablecontrols , this.Name); 
        }  

    }
}